<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function bar() {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve(123)
        }, 3000)
      })
    }

    // await关键字
    // 1. 只能在异步函数中使用
    async function foo() {
      console.log("--------")
      // await 后续返回一个Promise,那么会等待Promise有结果之后,才会继续执行后续代码
      const res1 = await bar()
      console.log('res1', res1)
      const res2 = await bar()
      console.log('res2', res2)
      console.log("--------")
    }
    foo()

  </script>
</body>

</html>